package com.site.util.taglib;

/**
 * I18nMessageTag.java
 * Product:BaseLayer
 * Version:1.0
 * Copyright 2009 by DNE
 * All Rights Reserved.
 */

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.site.util.MessageUtils;
import com.site.util.StringUtils;


/**
 * 读取国际化消息标签
 */
public class MessageTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	private String key; //消息key
	private String params; //参数，如果有多个参数用逗号隔开

	@Override
	public int doStartTag() throws JspException {
		String message="";
		if(!StringUtils.isEmpty(key)){
			String[] param=null;
			if(!StringUtils.isEmpty(params)){
				params = URLDecoder.decode(params);
				param=params.split(",");
			}
			message=MessageUtils.getMessageString(key,param, (HttpServletRequest)pageContext.getRequest());
		}
		try {
			pageContext.getOut().write(message);
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("I18nMessageTag标签出错！");
		}
		return super.doStartTag();
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getParams() {
		return params;
	}

	public void setParams(String params) {
		this.params = params;
	}
}
